<template>
	<view>
		<view class="head">
			<image src="../../static/images/arrow_left.png" mode="aspectFit" @tap="$back()"></image>
			<view class="">供应商详情</view>
			<view class="f32" @tap="goEdit()">编辑</view>
		</view>
		<view class="text">
			<view class="text-one">{{ info.name }}</view>
			<view class="text-two">负责人: {{ info.contact == '' ? '无' : info.contact }}</view>
			<view class="text-two">手机: {{ info.mobile == '' ? '无' : info.mobile }}</view>
			<view class="text-two">电话: {{ info.tel == '' ? '无' : info.tel }}</view>
			<view class="text-two">经营地址: {{ info.address == '' ? '无' : info.address }}</view>
		</view>

		<view class="detailBox">
			<view class="box-l">备注: {{ info.remark == '' ? '无' : info.remark }}</view>
			<view class="box-r"><image src="../../static/images/arrow_right.png" mode="aspectFit"></image></view>
		</view>
		<view class="detailBox">
			<view class="box-l">欠供应商款：¥{{ info.debt }}</view>
			<view class="box-t" @click="open"><image src="../../static/spe/01.png" mode="aspectFit"></image></view>
		</view>
		<view class="detailBox"  @tap="$open('reconciliation')">
			<view class="box-l">对账记录</view>
			<view class="box-r"><image src="../../static/images/arrow_right.png" mode="aspectFit"></image></view>
		</view>
		<view class="detailBox">
			<view class="box-l">采购记录</view>
			<view class="box-r"><image src="../../static/images/arrow_right.png" mode="aspectFit"></image></view>
		</view>
		<view class="butt">
			<view class="butt-one" @tap="goPay()">
				<image src="../../static/spe/06.png" mode="aspectFit"></image>
				付款
			</view>
			<view class="butt-one" @tap="call()">
				<image src="../../static/spe/07.png" mode="aspectFit"></image>
				电话
			</view>
			<view class="butt-one" style="border: none;" @click="goReturn()">
				<image src="../../static/spe/08.png" mode="aspectFit"></image>
				退货
			</view>
		</view>
		<!-- 编辑弹窗 -->
		<uni-popup ref="popup" type="center">
			<view class="addContent">
				<view class="box">
					<view class="tit tCenter f36 c333">请输入欠货供应商款数</view>
					<view class="input-box"><input type="text" :placeholder="info.debt" v-model="debt" /></view>
					<view class="input-box"><input type="text" placeholder="请输入备注信息(选填)" v-model="remark" /></view>
					<view class="btn f30 tCenter">
						<view class="dropBtn" @click="close">取消</view>
						<view class="submit" @click="define">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
export default {
	components: {
		uniPopup
	},
	data() {
		return {
			supplierId: '',
			debt: '', //欠供应商款
			remark: '', //备注
			info: {}
		};
	},
	onShow() {},
	onLoad(option) {
		this.supplierId = option.id,
		 this.getInfo(), 
		 uni.setStorageSync('supplierId', this.supplierId);
	},
	methods: {
		open() {
			this.$refs.popup.open();
		},
		define() {
			let that = this;
			that.$ajax('api/v1.supplier/accountLogAdjust', {
				supplier_id: that.supplierId,
				remark: that.remark,
				debt: that.debt
			}).then(res => {
					if (res.code == 1) {
						that.$sToast('修改成功');
						setTimeout(function() {
							that.$refs.popup.close();
							that.getInfo();
						}, 1500);
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		},
		close() {
			this.$refs.popup.close();
		},
		goPay(){
			uni.navigateTo({
				url:'./supplierpayment?id='+this.supplierId
			}) 
		},
		call(){
			uni.makePhoneCall({
			    phoneNumber: this.info.tel 
			});
		},
		goReturn(){
			uni.setStorageSync('name',this.info.name)
			uni.navigateTo({
				url:'./supplierReturns'
			})
		},
		
		//供应商详情

		getInfo() {
			let that = this;
			that.$ajax('api/v1.supplier/info', {
				supplier_id: that.supplierId
			})
				.then(res => {
					if (res.code == 1) {
						that.info = res.result;
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		},
		goEdit() {
			if (this.info.is_retail == 1) {
				uni.showModal({
					title: '温馨提示',
					content: '零散供应商的信息不允许被修改',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			} else {
				uni.navigateTo({
					url: 'supplierinfo'
				});
			}
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f7f4f8;
}
.head {
	line-height: 88rpx;
	background-color: #249af6;
	color: #ffffff;
	display: flex;
	justify-content: space-between;
	padding: 55rpx 30rpx 0 30rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 500;
	image {
		width: 22rpx;
		height: 39rpx;
		margin-top: 25rpx;
	}
}
.text {
	margin-top: 20rpx;

	background-color: #ffffff;
	padding: 40rpx 32rpx;
	box-sizing: border-box;
	.text-one {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 36rpx;
		margin-bottom: 34rpx;
	}
	.text-two {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		line-height: 60rpx;
	}
}
.detailBox {
	height: 110rpx;
	line-height: 110rpx;
	background-color: #ffffff;
	margin-top: 30rpx;
	display: flex;
	justify-content: space-between;
	padding: 0 30rpx;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	image {
		width: 18rpx;
		height: 33rpx;
		vertical-align: middle;
		margin-left: 20rpx;
	}
	.box-r {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
	}
	.box-t {
		image {
			width: 41rpx;
			height: 38rpx;
		}
	}
}
.butt {
	box-sizing: border-box;
	width: 100%;
	height: 110rpx;
	background-color: #ffffff;
	position: fixed;
	bottom: 0;
	display: flex;
	align-items: center;
	font-size: 32rpx;
	color: #333;
	padding:30rpx 0;
	font-family: PingFang SC;
	font-weight: 500;
	line-height: 36rpx;
	border-top: 2rpx #eee solid;

	image {
		width: 44rpx;
		height: 44rpx;
		vertical-align: middle;
		margin-right: 20rpx;
	}
	.butt-one {
		width: 33%;
		border-right: 2rpx solid #ddd;
		text-align: center;
	}
}
</style>
